/*用户自定义配置模块*/
//
import api from '@/api/api';
import {
  MERCHANT_INFO
} from '@/utils/constant';
// 全局配置
let config = {};

let getConfig = async () => {
  let merchantInfo =  uni.getStorageSync(MERCHANT_INFO);
  let json = await api.customize({
    method: 'POST',
    query: {
      "cloudMerchantId": merchantInfo.cloudMerchantId,
      "cloudMerchantStoreId": merchantInfo.cloudMerchantStoreId,
      "cloudStoreConfigtypeId": merchantInfo.cloudStoreConfigtypeId
    }
  });
  config = JSON.parse(json.data.cloudStoreConfigText);
};


let setNavigation = async () => {
  /*uni.setNavigationBarColor({
    frontColor: '#000000',
    backgroundColor: '#ffffff',
    complete: res =>{
      console.log(res)
    }
  });*/
  /*顶部导航配置*/
  /*uni.setNavigationBarColor({
    frontColor: config.navigation.NavigationBarTextColor,
    backgroundColor: config.navigation.NavigationBarColor,
    complete: res =>{
      console.log(res)
    }
  });*/

};

let setTabbar = async () => {
  /*tabbar配置*/
  uni.setTabBarStyle({
    color: config.tabbar.defaultColor,
    selectedColor: config.tabbar.selectedColor,
    backgroundColor: config.tabbar.backgroundColor,
    borderStyle: config.tabbar.borderStyle,
    complete: res =>{
      // console.log(res)
    }
  });
  /*设置tabbar每一项*/
  for (let i = 0;i < config.tabbar.item.length; i++) {
    // console.log(config.tabbar.item);
    if(config.tabbar.item[i].switchValue){
      uni.setTabBarItem({
        index: i,
        text: config.tabbar.item.text,
        iconPath: config.tabbar.item.icon,
        selectedIconPath: config.tabbar.item.selectedIcon,
        complete: res=>{
          // console.log(res)
        }
      })
    }
  }
};

/*导出自定义配置*/
export default {
  setNavigation,
  getConfig,
};
